package net.guruqu.rvoView;

import java.awt.Dimension;
import java.awt.DisplayMode;
import java.awt.Toolkit;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import org.lwjgl.opengl.Display;

import com.jme.math.Vector2f;

public class MasterTest {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		ConfigFile properties = new  ConfigFile();
		properties.load(new FileReader("Sample.conf"));
		LookAndFeelInfo[] laf = UIManager.getInstalledLookAndFeels();
		try {
			UIManager
					.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Splash splash = new Splash();
		final ModelRepository modelRepository = new ModelRepository();
		modelRepository.setMonitor(splash);
//		modelRepository.getLoadList().put("lily", "lily.xml");
//		modelRepository.getLoadList().put("model", "model.txt");
		modelRepository.getLoadList().put("env", properties.getProperty("envModel"));
//		modelRepository.getLoadList().put("sauce", "x_saucer.xml");
//		modelRepository.getLoadList().put("haus", "haus.xml");
//		modelRepository.getLoadList().put("test", "maxTest.xml");
		modelRepository.getLoadList().put("agent", properties.getProperty("agentModel"));

		modelRepository.loadModel();
		modelRepository.waitForLoad();
		// ModelPreLoaderTest loaderTest = new
		// ModelPreLoaderTest(modelRepository);
		// TODO Auto-generated method stub
		GroundDefComponent gcomponent = null;
		JFrame f1 = null, f2 = null, f3 = null;
		{
			JFrame f = new JFrame();
			f1 = f;
			gcomponent = new GroundDefComponent(modelRepository);
			f.getContentPane().add(gcomponent);
			f.pack();
			f.setVisible(true);
			f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			f.setSize(400, 400);
			f.setResizable(false);
		}
		{
			JFrame f = new JFrame();
			f2 = f;
			MapDefComponent component = new MapDefComponent(modelRepository);
			component.defView.groundLevelView = gcomponent.defView;
			f.getContentPane().add(component);
			f.pack();
			f.setVisible(true);
			f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			f.setLocation(400, 0);
			f.setSize(600, 700);
		}
		{
			JFrame f = new JFrame();
			f3 = f;
			SimulationViewComponent component = new SimulationViewComponent(
					modelRepository);
			component.normalFrame=f;
			f.getContentPane().add(component);
			f.pack();
			f.setVisible(false);
			f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

			// RvoSetupInfo info = new RvoSetupInfo();
			// {
			// MapAgent ma1 = new MapAgent();
			// ma1.setPosition(new Vector2f(0, 0));
			// ma1.setGoal(new Vector2f(400, 100));
			// info.getMapAgents().add(ma1);
			// }
			// component.simulationView.setupScenario(info);
			// info.get
			// JFrame f = new JFrame();
			// JmeContext comp = ModelUtil.createCanvas(640, 480, null);
			// f.getContentPane().add(comp.getCanvas());
			// f.setSize(640,480);
			// f.setVisible(true);
			// f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			//			
			// try {
			// comp.waitFor();
			// } catch (InterruptedException e) {
			// // TODO Auto-generated catch block
			// e.printStackTrace();
			// }
			// SimulationView simulationView = new SimulationView(new
			// HashMap<String,
			// String>(),modelRepository);
			// simulationView.setCanvas(comp);
		}
		{
			Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
			int w=d.width;int h=d.height;
			SwitchingPanel panel = new SwitchingPanel();
			panel.mapDefineFrames = new JFrame[] { f1, f2 };
			panel.simulationFrame = f3;
			panel.setVisible(true);
			panel.setLocation(0,h-panel.getHeight()-100);
		}
	}
}
